package moviePack;
import java.io.FileReader;
import java.io.LineNumberReader;
import java.util.ArrayList;


public class ColonDelimitedMovieFinder implements IMovieFinder{
	private String filename;
	
	public ColonDelimitedMovieFinder(){
		this.filename = "movies.txt";
	}
	
	public ArrayList<Movie> findall(){

		ArrayList<Movie> readMovies = new ArrayList<Movie>();	
		
		try {
			FileReader fr = new FileReader(this.filename);
			LineNumberReader lnr = new LineNumberReader(fr); 
	   
			String line;
			
	   
			while((line = lnr.readLine()) != null){
				//System.out.print(line);
				Movie tmpMovie = new Movie();
				tmpMovie.setTitle(line.substring(0, line.indexOf(":")));
				tmpMovie.setDirector(line.substring(line.indexOf(":")+1,line.length()));
				
				readMovies.add(tmpMovie);
			}
	   
		}catch(Exception e2) {
			System.out.println("Fehler beim Lesen aus der Datei");
		}

		
		return readMovies;
	}
	
	
}
